package jubaozhu.extra.base;

import jubaozhu.domain.User;
import org.springframework.web.multipart.MultipartFile;
import zhibi.frame.context.Constant;
import zhibi.frame.springmvc.base.AbstractController;
import zhibi.utils.io.FileUtils;

public class AdminBaseController extends AbstractController {

    /**
     * 登录后台用户
     *
     * @return
     */
    protected User sessionAdmin() {
        return (User) session.getAttribute(Constant.SESSION.ADMIN);
    }

    /**
     * @param file
     * @return
     */
    protected String saveFile(MultipartFile file) {
        String img = FileUtils.saveFile(file, getFilePath(), "IMG");
        return "/" + img;
    }


    protected String getFilePath() {
        // return "E:\\cloud\\projects\\private\\image-manage\\src\\main\\resources\\data\\";
        return request.getServletContext().getRealPath("/WEB-INF/classes/data") + "/";
    }

}
